<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
window.onload = function ()
{
			var oTab = document.getElementById('tab1');
	
			var oName = document.getElementById('txt1');
			var oAge = document.getElementById('txt2');
			var oBtn = document.getElementById('btn1');
	
			var rowNum = oTab.tBodies[0].rows.length+1;
	
			oBtn.onclick = function()
			{
					var oTr = document.createElement('tr');
				
					var oTd = document.createElement('td');
					//oTd.innerHTML = oTab.tBodies[0].rows.length+1;
					oTd.innerHTML = rowNum++;
					oTr.appendChild(oTd);
					
					oTd = document.createElement('td');
					oTd.innerHTML = oName.value;
					oTr.appendChild(oTd);
				
					oTd = document.createElement('td');
					oTd.innerHTML = oAge.value;
					oTr.appendChild(oTd);
				
					oTd = document.createElement('td');
					oTd.innerHTML = '<a href="javascript:;">删除</a>'
					oTr.appendChild(oTd);
				
					oTd.getElementsByTagName('a')[0].onclick = function()
					{
							//alert(this.parentNode.parentNode.cells[0].innerHTML);
							oTab.tBodies[0].removeChild(this.parentNode.parentNode);
					};
				
					oTab.tBodies[0].appendChild(oTr);
				
			};
			
};
</script>
</head>

<body>
Name: <input type="text" id="txt1">
age: <input type="text" id="txt2">
<input type="button" id="btn1">
<table id="tab1" border='1' width='500'>
	<thead>
		<td>ID</td>
		<td>姓名</td>
		<td>年龄</td>
		<td>操作</td>
	</thead>
	<tbody>
		<tr>
			<td>1</td>
			<td>Albert</td>
			<td>25</td>
			<td></td>
		</tr>
		
		<tr>
			<td>2</td>
			<td>test</td>
			<td>22</td>
			<td></td>
		</tr>
		
		<tr>
			<td>3</td>
			<td>test2</td>
			<td>23</td>
			<td></td>
		</tr>
		
		<tr>
			<td>4</td>
			<td>test3</td>
			<td>26</td>
			<td></td>
		</tr>
		
		<tr>
			<td>5</td>
			<td>test4</td>
			<td>28</td>
			<td></td>
		</tr>
	</tbody>
	
</table>
</body>
</html>
